﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Data.SqlServerCe;
//using Gma.UserActivityMonitor;
using System.Windows.Media.Effects;




namespace MercuryFE
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class GameDetails : MyWindow
    {

        private int _gameId = -1;

        public GameDetails(int gameId)
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Main_Loaded);
            this._gameId = gameId;


            string winStyle = ClientLib.getConfig("Window Style");
            if (winStyle == "fullscreen")
            {
                this.WindowState = System.Windows.WindowState.Maximized;
                this.WindowStyle = System.Windows.WindowStyle.None;
                this.AllowsTransparency = true;
                this.Background = Brushes.Transparent;
                this.Topmost = true;
            }

        }

        void Main_Loaded(object sender, RoutedEventArgs e)
        {



            // get the size of the font in the heading, and use this

            ClientLib.generateDetails(_gameId, ref Viewer, ref tbName, this);

            App.InitialiseNavigation(false);
        }



        public override void DoNavigation(NavigationHook.NavigationTask navigationTask, bool normalSpeed)
        {
            bool changeDocument = false;
            bool scrollDocument = false;
            bool scrollDown = true;

            

            switch (navigationTask)
            {
                case NavigationHook.NavigationTask.Left:
                    if (Viewer.SelectedIndex != 0)
                    {
                        Viewer.ScrollIntoView(Viewer.Items[--Viewer.SelectedIndex]);
                        changeDocument = true;
                    }
                    break;
                case NavigationHook.NavigationTask.Right:
                    if (Viewer.SelectedIndex != Viewer.Items.Count - 1)
                    {
                        Viewer.ScrollIntoView(Viewer.Items[++Viewer.SelectedIndex]);
                        changeDocument = true;
                    }
                    break;
                case NavigationHook.NavigationTask.Up:
                    scrollDocument = true;
                    scrollDown = false;
                    break;
                case NavigationHook.NavigationTask.Down:
                    scrollDocument = true;
                    break;
                case NavigationHook.NavigationTask.Select:
    
                    break;
                case NavigationHook.NavigationTask.Back:
                    this.Close();
                    break;
                case NavigationHook.NavigationTask.Pause:
   
                    break;

            }

            if (changeDocument)
            {
                FlowDocument item = (FlowDocument)Viewer.SelectedItem;
                item.Focus();
            }

            if (scrollDocument)
            {
                FlowDocument doc = (FlowDocument)Viewer.SelectedItem;
                FlowDocumentPageViewer docViewer = (FlowDocumentPageViewer)doc.Parent;
                if (scrollDown)
                {
                    if (docViewer.CanGoToNextPage)
                    {
                        docViewer.NextPage();
                    }
                }
                else
                {
                    if (docViewer.CanGoToPreviousPage)
                    {
                        docViewer.PreviousPage();
                    }
                }
            }

        }



    }






}
